package club.gskj.gulimall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName MyThreadConfig
 * @Description TODO
 * @Author 康纳
 * @Date 2021-03-14
 */

/**
 * 自定义 系统线程池
 */
//@EnableConfigurationProperties(ThreadPoolConfigProperties.class 这里已经将配置文件放入IOC容器，可不用指定
@Configuration
public class MyThreadConfig {

    /***
     *
     * @param properties 可自定义参数值
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties properties) {
        return new ThreadPoolExecutor(
                properties.getCoreSize(),
                properties.getMaxSize(),
                properties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
}
